package com.clkj.zhonghui.dao.points;

import com.clkj.zhonghui.pojo.points.RebateRelations;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @Author 周佳润
 * @Date 2024/9/4 上午9:43
 */
@Repository
public interface RebateRelationsMapper extends Mapper<RebateRelations> {

    @Update("update t_zh_rebateRelations set surplus_point -=#{usedYh} where user_id = #{userId}")
    void updatePayUser(Integer userId, Double usedYh);

    @Update("UPDATE t_zh_rebateRelations SET surplus_point = surplus_point + #{usedYh}, total_point = total_point + #{usedYh} WHERE user_id = #{userId};")
    void updatePointsPayUser(Integer userId, Double usedYh);

    @Select("SELECT a.* ,b.user_name AS userName FROM t_zh_rebateRelations a LEFT JOIN t_zh_user b ON a.user_id = b.user_id WHERE a.user_id = #{userId}")
    RebateRelations listRelations(Integer userId);

    @Select("SELECT a.* ,b.user_name AS userName FROM t_zh_rebateRelations a LEFT JOIN t_zh_user b ON a.user_id = b.user_id WHERE a.referrer_id = #{userId}")
    List<RebateRelations> listLowerUser(Integer userId);

    @Update("update t_zh_rebateRelations set note = 1 where user_id = #{userId}")
    void updatePointsNode(Integer userId);
}
